﻿using DapperExtensions.Mapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Interface.Dapper
{
    public static class DapperConfig
    {
        public static void MapperInit()
        {
            DapperExtensions.DapperExtensions.DefaultMapper = typeof(DefaultMapper<>);
        }
    }

    public class DefaultMapper<T> : AutoClassMapper<T> where T : class
    {
        public DefaultMapper()
        {
            string tableName = EntityType.Name;

            var attr = EntityType.GetCustomAttributes(false).Where(m => m.GetType().Name == "TableAttribute").SingleOrDefault() as dynamic;

            if (attr != null)
            {
                tableName = attr.Name;
            }

            Table(tableName);
        }
    }
}
